#include <bits/stdc++.h>

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T;
    cin >> T;
    while (T --) {
        int x, y, _, q;
        cin >> x >> y >> _ >> q;
        if (_ << 1 <= q) cout << (x + y - 2) * _ << '\n';
        else {
            int minn = min(x, y), maxn = max(x, y) - minn;
            if (q < _) cout << minn * q + (maxn & 1 ? maxn * q - q + _: maxn * q) << '\n';
            else cout << minn * q + maxn * _ << '\n';
        }
    }
    cout << endl;
    system("pause");
    return 0;
}